package com.hisan.freeride.home.adapter;

import com.github.library.BaseQuickAdapter;
import com.github.library.BaseViewHolder;
import com.hisan.freeride.R;
import com.hisan.freeride.common.utils.CollectionUtils;
import com.hisan.freeride.home.model.Connection;

import java.util.List;

/**
 * 创建时间 : 2017/6/8
 * 创建人：yangyingqi
 * 公司：嘉善和盛网络有限公司
 * 备注：添加紧急联系人适配器
 */
public class ConnectionAdapter extends BaseQuickAdapter<Connection,BaseViewHolder> {

    private ButtonClickListener mButtonClickListener;
    private ItemClickListener mItemClickListener;

    public ConnectionAdapter(List<Connection> data) {
        super(R.layout.connection_item,data);
    }


    @Override
    protected void convert(BaseViewHolder holder, final Connection item) {
        holder.getView(R.id.intervalLin).setOnClickListener(v -> {
                if (!CollectionUtils.isNullOrEmpty(mItemClickListener)){
                    mItemClickListener.onItemClick(item);
                }
        });
        holder.setText(R.id.name, item.getName());
        holder.setText(R.id.phone, item.getMobile());
        holder.setText(R.id.id, item.getId()+"");
        holder.getView(R.id.delete).setOnClickListener(v -> {
            if (mButtonClickListener!=null){
                mButtonClickListener.onClick(item);
            }
        });
    }


    public void setButtonClickListener(ButtonClickListener listener) {
        mButtonClickListener = listener;
    }
    public void setItemClickListener(ItemClickListener listener) {
        mItemClickListener = listener;
    }

    /**
     * 按钮的点击监听
     */
    public interface ButtonClickListener {
        void onClick(Connection data);
    }

    /**
     * item的点击监听
     */
    public interface ItemClickListener {
        void onItemClick(Connection data);
    }
}
